package com.wellsantos.dgwt.papelaria.client.view;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
import com.googlecode.dgwt.client.dijit.Composite;
import com.googlecode.dgwt.client.dijit.Container;
import com.googlecode.dgwt.client.dijit.Dijit;
import com.googlecode.dgwt.client.dijit.form.Button;
import com.googlecode.dgwt.client.dijit.layout.HFlexPanel;
import com.googlecode.dgwt.client.dijit.theme.Theme;
import com.googlecode.dgwt.client.dojo.URL;
import com.wellsantos.dgwt.client.view.MainViewBase;
import com.wellsantos.dgwt.client.view.MenuViewBase;
import com.wellsantos.dgwt.home.client.Home;
import com.wellsantos.dgwt.papelaria.client.Papelaria;


public class PapelariaView extends BaseView implements MainViewBase {

    
    private HFlexPanel mainPanel = new HFlexPanel();
    
    private Composite cadernoPanel = new Composite(new URL("papelaria/view/caderno.html"));
    
    private Container cadernoHeader = cadernoPanel.bindAttachmentAsContainer("headerElement");
    
    @SuppressWarnings("unused")
    private Container cadernoFooter = cadernoPanel.bindAttachmentAsContainer("footerElement");
    
    private Image empresaLogotipo = IMAGE_RESOURCES.logotipoPrincipal().createImage();
    
    private MenuView menuView = new MenuView();
    
    
    
    public PapelariaView() {
        
        // criar o caderno
        
        cadernoPanel.setStyleSheet(Papelaria.getTheme().cadernoPanel());
        cadernoPanel.setHeight("100%");
        
        cadernoHeader.add(empresaLogotipo);
        
        cadernoPanel.add("<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />");
        cadernoPanel.add(new Button("Teste Voltar", new ClickHandler() {
            public void onClick(ClickEvent event) {
                Home.getMainView().show();
            }
        }));
        

        // painel principal
        
        mainPanel.setHeight("100%");
        mainPanel.add(cadernoPanel, 1);
        mainPanel.add(menuView.getWidget());
        
        mainPanel.getWidgetTd(cadernoPanel).getStyle().setProperty(
                "padding", "30px 0px 0px 10px");
                mainPanel.getWidgetTd(menuView.getWidget()).getStyle().setProperty(
                        "padding", "30px 10px 0px 10px");
                mainPanel.getWidgetTd(menuView.getWidget()).setVAlign(
                        HasVerticalAlignment.ALIGN_TOP.getVerticalAlignString());
    }

    
    @Override
    public void onShow(){
        Dijit.setTheme(Papelaria.getTheme());
    }

    
    @Override
    public void onHide(){
        Dijit.setTheme(Theme.getDefaultTheme());
    }
    
    
    @Override
    public String getTitle() {
        return APPLICATION_RESOURCES.windowTitle();
    }

    
    @Override
    public Widget getWidget() {
        return mainPanel;
    }


    @Override
    public MenuViewBase getMenuView() {
        return menuView;
    }


    @Override
    public void setContent(Widget content, String label) {
        cadernoPanel.clear();
        cadernoPanel.add(content);
    }

}
